package com.moorror.codegenvel.common.table;

import com.intellij.ui.dualView.TreeTableView;
import com.intellij.ui.treeStructure.treetable.ListTreeTableModelOnColumns;

import javax.swing.*;
import javax.swing.tree.TreeCellRenderer;
import java.awt.*;

/**
 * @Author jiyanghuang
 * @Date 2025/9/21 13:28
 * 这么写只是为了设置渲染器 MRHighlightableCellRenderer 专为tree节点设置
 */
public class MRTreeTableView extends TreeTableView {
    public MRTreeTableView(ListTreeTableModelOnColumns treeTableModel) {
        super(treeTableModel);
        this.setTreeCellRenderer(new TreeCellRenderer() {
            /**
             * 只为渲染树展开与闭合节点
             */
            private final TreeCellRenderer myBaseRenderer = new MRHighlightableCellRenderer();

            public Component getTreeCellRendererComponent(JTree tree1, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
                JComponent result = (JComponent)this.myBaseRenderer.getTreeCellRendererComponent(tree1, value, selected, expanded, leaf, row, hasFocus);
                result.setOpaque(!selected);
                return result;
            }
        });
    }
}
